package com.pizza.abstrait;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Hashtable;

import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

import com.pizza.control.ClientBean;
import com.pizza.control.CommandeBean;
import com.pizza.model.Diametre;
import com.pizza.model.Ingredient;
import com.pizza.model.Pizza;

/**
 * Class AbstractPersonnaliser, classe qui permet la personnalisation d'une pizza.
 *
 */
public class AbstractPersonnaliser implements Serializable 
{
	protected AbstractPizza pizzaPerso;
	protected ArrayList<Ingredient> listIngredients;
	
	protected int indexPrix=0; 
	
	private SelectItem[] prices = {
		      new SelectItem(0, "1Pers. 11.00€" ),
		      new SelectItem(1, "2Pers. 13.50€" ),
		      new SelectItem(2, "4Pers. 15.00€" )
	};
	
	public SelectItem[] getPrices() {
		return prices;
	}

	public void setPrices(SelectItem[] prices) {
		this.prices = prices;
	}

	public AbstractPizza getPizzaPerso() {
		return pizzaPerso;
	}

	public void setPizzaPerso(AbstractPizza pizzaPerso) {
		this.pizzaPerso = pizzaPerso;
	}

	public void Personnaliser( AbstractPizza _pizza )
	{
		FacesContext context = FacesContext.getCurrentInstance();
		ClientBean _client = (ClientBean) context.getExternalContext()
		.getSessionMap().get("clientBean");
		pizzaPerso = new Pizza(_pizza, _client);
	}
	
	public void addIngredient(Ingredient _ingredient)
	{
		if(! pizzaPerso.getIngredients().contains(_ingredient))
			pizzaPerso.addIngredient(_ingredient);
	}
	
	public void removeIngredient(Ingredient _ingredient)
	{
		if(pizzaPerso.getIngredients().contains(_ingredient))
			pizzaPerso.removeIngredient(_ingredient);
	}
	
	public void setNom(String nom)
	{
		pizzaPerso.setNom(nom);
	}
	
	public ArrayList<Ingredient> getIngredients() {
		return pizzaPerso.getIngredients();
	}
	
	public String ajouterPizzaPersoCommande() {
		FacesContext context = FacesContext.getCurrentInstance();
		CommandeBean commande = (CommandeBean) context.getExternalContext()
		.getSessionMap().get("commandeBean");
		
		if(commande != null) {
			commande.ajouterPizzaPanier(pizzaPerso, pizzaPerso.diametres.get(indexPrix).getDiametre());
		}
		return "pizzas";
	}

	public int getIndexPrix() {
		return indexPrix;
	}

	public void setIndexPrix(int indexPrix) {
		this.indexPrix = indexPrix;
	}

	public ArrayList<Ingredient> getListIngredients() {
		return listIngredients;
	}

	public void setListIngredients(ArrayList<Ingredient> listIngredients) {
		this.listIngredients = pizzaPerso.getIngredients();
	}

}
